﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PropertyMatch.aspx.cs" Inherits="PageTypeBuilderUI.Plugins.Admin.PropertyMatch" %>
<%@ Import Namespace="PageTypeBuilderUI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContentRegion" runat="server">
    <script type="text/javascript">
        function ToggleSelectAll(checkbox, updateButtonId, contains) {
            var checkBoxes = $('input:checkbox');

            for (i = 0; i < checkBoxes.length; i++) {
                var id = $(checkBoxes[i]).attr('id');

                if (id.indexOf(contains) == -1)
                    continue;

                $(checkBoxes[i]).attr('checked', $(checkbox).attr('checked'));
                var cssClass = id.indexOf('RemoveProperty_') != -1 ? 'ptbDeleteRow' : 'ptbUpdateRow';

                if ($(checkBoxes[i]).attr('checked'))
                    $(checkBoxes[i]).parent().parent().addClass(cssClass);
                else
                    $(checkBoxes[i]).parent().parent().removeClass(cssClass);
            }

            UpdateSelectAllCheckBox($(checkbox).attr('id'), updateButtonId, contains);
        }

        function UpdateSelectAllCheckBox(checkboxId, updateButtonId, contains) {
            var checkBox = $('#' + checkboxId);

            var checkBoxes = $('input:checkbox');
            var numberOfCheckBoxes = 0;
            var numberOfCheckBoxesChecked = 0;

            for (i = 0; i < checkBoxes.length; i++) {
                var id = $(checkBoxes[i]).attr('id');

                if (id.indexOf(contains) == -1)
                    continue;

                numberOfCheckBoxes++;

                var cssClass = id.indexOf('RemoveProperty_') != -1 ? 'ptbDeleteRow' : 'ptbUpdateRow';

                if ($(checkBoxes[i]).attr('checked')) {
                    $(checkBoxes[i]).parent().parent().addClass(cssClass);
                    numberOfCheckBoxesChecked++;
                }
                else
                    $(checkBoxes[i]).parent().parent().removeClass(cssClass);
            }
            $(checkBox).attr('checked', numberOfCheckBoxes > 0 && numberOfCheckBoxes == numberOfCheckBoxesChecked ? 'checked' : '');
            $('#' + updateButtonId).attr('disabled', numberOfCheckBoxesChecked > 0 ? '' : 'disabled')
        }

        function ConfirmUpdate() {
            return confirm("<%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/areYouSure")%>");
        }

        $(document).ready(function () {
            UpdateSelectAllCheckBox('RemovePropertySelectAll', '<%=BulkRemovePropertiesButton.ClientID%>', 'RemoveProperty_');
            UpdateSelectAllCheckBox('ChangePropertySelectAll', '<%=BulkUpdatePropertiesButton.ClientID%>', 'ChangeProperty_');
        });

    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainRegion" runat="server">
    <style>
        .override td { padding: 0 5px; }
        .pageTypeDiv, .ptbTable { margin-bottom: 5px!important }
        .ptbCenterAlignedCell { text-align:center }
        .ptbDeleteRow { background-color:#FAA61D!important }
        .ptbUpdateRow { background-color:#BCED91!important }
        .ptbRemovePropertiesButton { background-color:#FAA61D!important }
        .ptbUpdatePropertiesButton { background-color:#BCED91!important }
    </style>
    <p>
    <%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/showOnlyMismatches")%>: <asp:CheckBox id="CheckBoxOnlyMissmatch" autopostback="true" checked="true" runat="server"></asp:CheckBox><br />  
    <%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/togglePropertiesThatNeedRemoving")%>: <input type="checkbox" id="RemovePropertySelectAll" value="<%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/selectAll")%>" title="<%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/selectAll")%>" onclick="javascript:ToggleSelectAll(this, '<%=BulkRemovePropertiesButton.ClientID%>', 'RemoveProperty_');" /><br />
    <%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/togglePropertiesThatNeedUpdating")%>: <input type="checkbox" id="ChangePropertySelectAll" value="<%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/selectAll")%>" title="<%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/selectAll")%>" onclick="javascript:ToggleSelectAll(this, '<%=BulkUpdatePropertiesButton.ClientID%>', 'ChangeProperty_');" />
    <br /><br />
    <asp:Button ID="BulkRemovePropertiesButton" CssClass="ptbRemovePropertiesButton" runat="server" Text='<%#LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/removeProperties")%>' onclick="RemoveProperties" />&nbsp;
    <asp:Button ID="BulkUpdatePropertiesButton" CssClass="ptbUpdatePropertiesButton" runat="server" Text='<%#LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/updatePropertyTypes")%>' onclick="UpdateProperties" OnClientClick="return ConfirmUpdate();" />
    <br /><br />
    </p>    
    <asp:Repeater ID="RepeaterPageTypes" runat="server">
        <ItemTemplate>

            <asp:PlaceHolder id="Test" runat="server">
                <div class="pageTypeDiv">
                    <b><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/pageType")%>: <a href="<%= EPiServer.UriSupport.ResolveUrlFromUIBySettings("Admin")  %>/EditPageType.aspx?typeId=<%# DataBinder.Eval(Container.DataItem, "ID") %>" target="_blank"><%# DataBinder.Eval(Container.DataItem, "Name") %></a>
                </div>
                <table class="epi-default ptbTable">
                    <thead>
                        <tr>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/propertyName")%></th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/episerverType")%></th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/pageTypeBuilderType")%></th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/message")%></th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/action")%></th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/remove")%> </th>
                            <th><%=LanguageHelper.Translate("/pageTypeBuilderPropertyMatch/updateType")%></th>
                        </tr>
                    </thead>
                    <tbody>
                    
                        <asp:Repeater ID="RepeaterProperties" runat="server">
                            <HeaderTemplate></HeaderTemplate>
                            <ItemTemplate>                            
                                <tr id="TableRow" runat="server" enableviewstate="false">
                                    <td><%# DataBinder.Eval(Container.DataItem, "Name") %></td>
                                    <td><%# ((EPiServer.DataAbstraction.PageDefinition)Container.DataItem).Type != null && ((EPiServer.DataAbstraction.PageDefinition)Container.DataItem).Type.DefinitionType != null ? ((EPiServer.DataAbstraction.PageDefinition)Container.DataItem).Type.DefinitionType.Name : ""%></td>
                                    <td><asp:Literal ID="LiteralType" runat="server"></asp:Literal></td>
                                    <td><asp:Literal ID="LiteralMissmatch" runat="server"></asp:Literal></td>
                                    <td align="center"><asp:LinkButton ID="LinkButtonRemove" runat="server"></asp:LinkButton><asp:HyperLink id="HyperLinkAction" runat="server" /></td>
                                    <td align="center" class="ptbCenterAlignedCell"><asp:CheckBox ID="RemovePropertyCheckBox" runat="server" Visible="false" /></td>
                                    <td align="center" class="ptbCenterAlignedCell"><asp:CheckBox ID="ChangePropertyCheckBox" runat="server" Visible="false" /></td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate></FooterTemplate>
                        </asp:Repeater>       
                    </tbody>
                </table>
                <br />
            </asp:PlaceHolder>
        </ItemTemplate>
    </asp:Repeater>
    <p>&nbsp;</p>
</asp:Content>
